home *** CD-ROM | disk | FTP | other *** search
- /*
- Copyright © 1988,1989,1990 by
- David A. Surovell,
- Succinct Systems
- 433 Huronview
- Ann Arbor, MI 48103
- (313) 663-4903
- AppleLink: (none yet)
-
- ••• All Rights Reserved. •••
-
- File: VBLTasks.c
- Model: THINK C 4.0, MPW C 3.0, Aztec C 3.0
-
- ABSTRACT:
- vertical-blank task handling routines.
-
- NOTES:
- ---
-
- KNOWN BUGS:
- ---
-
- HISTORY:
- DAS 01-Jun-90 did it here first
- */
-
- #include <Color.h>
- #include <DeviceMgr.h>
- #include <SlotMgr.h>
- #include <VRetraceMgr.h>
- #include "VBLTasks.h"
-
- static ProcPtr curVBHandler = NULL;
- static Boolean vbTaskStatus = FALSE;
-
-
- /* MPW C glue, because there is no inline assembler */
- #ifdef _MPWC_
- VBLTaskInfo *GetVBLInfo( void ) = { 0x2008 }; /* MOVE.L A0,D0 */
- #endif _MPWC_
-
-
- /*
- ** install generic task stub on specified GDevice:
- ** task info ptr returned on success
- ** NULL returned on failure
- */
- VBLTaskInfoPtr InstallVBTask(
- GDHandle theGDev )
- {
- SysEnvRec theWorld;
- QElemPtr theQueueItem;
- VBLTaskInfoPtr curVBLInfo;
- VBLTask *vbInt;
- OSErr errStat;
- unsigned short curSlotID;
-
- (void)SysEnvirons( curSysEnvVers, &theWorld );
-
- curVBLInfo = (VBLTaskInfoPtr)NewPtrClear( sizeof(VBLTaskInfoRec) );
- if (curVBLInfo == NULL)
- return NULL;
-
- /* facilitates “better” access to private VB info */
- vbInt = (VBLTask*)curVBLInfo;
- vbInt->qType = vType;
- vbInt->vblAddr = (ProcPtr)(&DispatchVBTask);
-
- /* execute every VBLANK_RATE vertical blanks */
- vbInt->vblCount = VBLANK_RATE;
- vbInt->vblPhase = 0;
- curVBLInfo->A5World = SetCurrentA5();
-
- theQueueItem = (QElemPtr)curVBLInfo;
- if (theWorld.hasColorQD)
- {
- if (theGDev == NULL)
- theGDev = GetMainDevice();
-
- /* install VBL on slot of main device (screen with menu bar) */
- curSlotID = GDGetSlotID( theGDev );
- errStat = SlotVInstall( theQueueItem, curSlotID );
- }
- else
- /* old black & white Mac */
- errStat = VInstall( theQueueItem );
-
- if (errStat == noErr)
- {
- vbTaskStatus = TRUE;
- return curVBLInfo;
- }
- else
- {
- vbTaskStatus = FALSE;
- DisposPtr( (Ptr)curVBLInfo );
- return NULL;
- }
- }
-
-
- /*
- ** obtain slot number of specified GDevice
- */
- unsigned short GDGetSlotID(
- GDHandle theGDev )
- {
- AuxDCEHandle theDrvrHdl;
- short slotNum;
-
- if (theGDev != NULL)
- {
- theDrvrHdl = (AuxDCEHandle)GetDCtlEntry( (**theGDev).gdRefNum );
- if (theDrvrHdl != NULL)
- return (**theDrvrHdl).dCtlSlot;
- }
-
- return 0x0000;
- }
-
-
- /*
- ** set A5 context, dispatch VBTask, refresh vbl counter
- ** including additional task handler
- */
- pascal void DispatchVBTask( void )
- {
- VBLTaskInfoPtr curVBLInfo;
- unsigned long oldA5;
-
- #ifdef THINK_C
- asm { move.l A0, curVBLInfo }
- #endif THINK_C
-
- #ifdef _MPWC_
- curVBLInfo = GetVBLInfo();
- #endif _MPWC_
-
- /* allow global variables to be properly referenced */
- oldA5 = SetA5( curVBLInfo->A5World );
-
- /* if task flag is still set, handle the VBL signal */
- if (vbTaskStatus)
- {
- /* reset the task counter so that this task will stay active */
- curVBLInfo->vbl.vblCount = VBLANK_RATE;
-
- /* perform any additional tasks here */
- /* remember not to perform any memory management functions */
- if (curVBHandler != NULL)
- (*curVBHandler)();
- }
-
- /* restore original A5 value */
- (void)SetA5( oldA5 );
- }
-
-
- /*
- ** install a routine to handle additional VB task activities:
- ** must be of type "void FunctionName( void )"
- */
- void SetVBHandler(
- ProcPtr theVBHandler )
- {
- curVBHandler = theVBHandler;
- }
-
-
- /*
- ** set flag to enable a VBTask to renew itself;
- ** clear to kill a running VBTask
- */
- void SetVBLTaskStatus(
- Boolean newTaskStatus )
- {
- vbTaskStatus = newTaskStatus;
- }
-
-